package com.hh.m15e.domain.vo;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hh.m15e.constant.InputParamConst;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 作者: Ⅹ玖
 * 创建日期：2025/2/21 14:25
 * 文档描述：接口输入报文格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class InputParamVo {
    private String infno;
    private String msgid;
    private String mdtrtareaAdmvs;
    private String insuplcAdmdvs;
    private String recerSysCode;
    private String devNo;
    private String devSafeInfo;
    private String cainfo;
    private String signtype;
    private String infver;
    private String opterType;
    private String opter;
    private String opterName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime infTime;
    private String fixmedinsCode;
    private String fixmedinsName;
    private String signNo;
    private String appId;
    private String encType;
    private String input;
    private String pwEcToken;

    public InputParamVo(String code,String signNo, Object object) {
        this.infno = code;
        this.signNo = signNo;
        this.input = JSONUtil.toJsonStr(object);
        setInputParamVo();
    }

    public InputParamVo(String code,String signNo, String insuplcAdmdvs,Object object) {
        this.infno = code;
        this.signNo = signNo;
        this.insuplcAdmdvs = insuplcAdmdvs;
        this.input = JSONUtil.toJsonStr(object);
        setInputParamVo();
    }

    // 数据初始化
    private static int count = 1; // 自增数字
    private void  setInputParamVo(){
//        this.infno = InputParamConst.INFNO;

        this.mdtrtareaAdmvs = InputParamConst.MDTRTAREA_ADMVS;
//        this.insuplcAdmdvs = InputParamConst.INSUPLC_ADMVS;
        this.recerSysCode = InputParamConst.RECER_SYS_CODE;
        this.devNo = InputParamConst.DEV_NO;
        this.devSafeInfo = InputParamConst.DEV_SAFE_INFO;
        this.cainfo = InputParamConst.CAINFO;
        this.signtype = InputParamConst.SIGNTYPE;
        this.infver = InputParamConst.INFVER;
        this.opterType = InputParamConst.OPTER_TYPE;
        this.opter = InputParamConst.OPTER;
        this.opterName = InputParamConst.OPTER_NAME;
//        this.infTime = InputParamConst.INF_TIME;
        this.fixmedinsCode = InputParamConst.FIXMEDINS_CODE;
        this.fixmedinsName = InputParamConst.FIXMEDINS_NAME;
//        this.signNo = InputParamConst.SIGN_NO;
        this.appId = InputParamConst.APP_ID;
        this.encType = InputParamConst.ENC_TYPE;
//        this.input = InputParamConst.INPUT;
        this.pwEcToken = InputParamConst.PW_ECTOKEN;
        // 设置msgid用fixmedinsCode+时间戳+自增数字
        this.msgid= this.fixmedinsCode +  LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + (String.format("%04d", count++));


    }
}
